// pages/goods-list/index.js
import {
    getNavigationbar
} from "../../api/index.js"
Page({
    options: {
        styleIsolation: "shared"
    },
    /**
     * 页面的初始数据
     */
    data: {
        nvaigateName: "供应商详情",
        nvaigateState: false,
        scrollViewHeight: 0,
        height: 0,
        numGood: 0,
        flag: false,
        goodsList: [],
        lineState: false,
        isSpecs: false,
        isAshow: false,
        isAshows: false,
        columns: [],
        history: [],
        subdata: {},
        kFlag: false,
        orderFlag: false,
        lowPrice: 0,
        highPrice: 0,
        // 价格
        priceData: {
            lowPrice: '',
            highPrice: ''
        },
        obj: {},
        isinternal: '', //是否进口
        keyword: '',
        navigateToUrl: '',
        scrollTop: 0,
        lisrcot: [],
        addStickyStyle: false,
        currentPage: 1, // 当前页码
        goodsbrand_activity: {} //供应商活动
    },
    onScrollViewScroll: function (e) {
        if (e.detail.scrollTop >= 190) { // 当滚动到200px位置时添加样式
            this.setData({
                isAshows: true,
                // scrollViewHeight:700
            });
        } else {
            this.setData({
                isAshows: false
            });
        }
        console.log('eeee', e.detail.scrollTop)
        // 在这里可以处理scroll-view滚动时的逻辑
    },
    nood() {
        console.log('点击', this.data.subdata)
        if (this.data.obj.shop_status == 0 || this.data.obj.shop_status == 1) {
            this.setData({
                isAhow: true,
            })
            return
        }
        wx.reLaunch({
            url: `/pages/goods_cart/index`,
        })

    },
    getShoppingCartList(item) {
        getNavigationbar({
            act: 'getcartsp',

        }).then(res => {
            console.log('购物车列表-一件代发', res)
            this.setData({
                numGood: res.numbers
            })

        });
    },
    /**
     * 选择筛选类目回调函数方法
     * @param {*} e 
     */
    // 数据处理函数，根据index和接口返回的数据处理columns和height
    // 处理选项切换事件
    handleOnTabs(e) {
        wx.nextTick(() => {
            this.setData({
                isAshow: true,
            })
        })
        const index = e.detail;
        const {
            brandList,
            catList,
            petTypeList
        } = this.data;
        let columns = [];
        let height = 0;
        console.log('点击', e)

        switch (index) {
            case 0:
                columns = brandList.map(element => ({
                    ...element,
                    type: 3
                }));
                height = 360;
                break;
            case 1:
                columns = catList.map(element => ({
                    ...element,
                    type: 2
                }));
                height = 170;
                break;
            case 2:
                columns = petTypeList.map(element => {
                    let numId;
                    switch (element.name) {
                        // 处理numId逻辑
                    }
                    return {
                        ...element,
                        type: 1,
                        numId: numId
                    };
                });
                height = 170;
                break;
            case 3:
                height = 170;
                break;
        }

        this.setData({
            columns,
            height
        });
    },
    /**
     * 蒙版
     * @param {*} e 
     */
    handlemaskClick(e, benblen) {
        if (e.detail == false) {
            this.setData({
                isAshow: false
            })
            return
        }
        console.log('1', e, benblen)
        this.setData({
            goodsList: []
        })
        console.log('e.detail11', e.detail, this.data.history)
        if (this.data.history.length == 0) {
            this.data.history.push({
                type: 1,
                data: []
            }, {
                type: 2,
                data: []
            }, {
                type: 3,
                data: []
            }, {
                type: 4,
                data: []
            });
        }

        e.detail.forEach((item, index) => {
            if (index == 0) {
                this.data.brandList.map(element => element.checked = false)
                this.data.brandList.forEach(element => {
                    item.selectInfo.forEach(info => {
                        if (info.brandid == element.brandid) {
                            element.checked = true;
                        }
                    })
                })
                this.data.history.forEach(element => {
                    if (element.type == 3) {
                        element.data = item.selectInfo
                    }
                })
            } else if (index == 1) {
                this.data.catList.map(element => element.checked = false)
                this.data.catList.forEach(element => {
                    item.selectInfo.forEach(info => {
                        if (info.id == element.id) {
                            element.checked = true;
                        }
                    })
                })
                this.data.history.forEach(element => {
                    if (element.type == 2) {
                        element.data = item.selectInfo
                    }
                })
            } else if (index == 2) {
                this.data.petTypeList.map(element => element.checked = false)
                this.data.petTypeList.forEach(element => {
                    item.selectInfo.forEach(info => {
                        if (info.id == element.id) {
                            element.checked = true;
                        }
                    })
                })
                this.data.history.forEach(element => {
                    if (element.type == 1) {
                        element.data = item.selectInfo
                    }
                })
            } else if (index == 3) {
                this.data.history.forEach(element => {
                    if (element.type == 4) {
                        element.data = this.data.isinternal == 2 ? [{
                            id: 1,
                            name: '进口商品'
                        }] : item.selectInfo
                    }
                })
            }
        })
        wx.nextTick(() => {
            this.setData({
                history: this.data.history,
                currentPage: 1
            })
        })
        // 使用map方法取出id并组成字符串
        let pettype = this.data.history[0].data.map(item => {
            if (item.numId) {
                return item.numId;
            } else if (item.id) {
                return item.id;
            }
        }).join(',');
        let scatid = this.data.history[1].data.map(item => item.id).join(',');
        let brandid = this.data.history[2].data.map(item => item.brandid).join(',');
        let activityregion = this.data.history[3].data.map(item => item.id);
        let combinedString = ''
        if (this.data.lowPrice != '' && this.data.highPrice != '') {
            combinedString = this.data.lowPrice + ',' + this.data.highPrice;
        } else {
            combinedString = ''
        }
        console.log('pettype', pettype, scatid, brandid, combinedString); // 输出结果为 "96,4,9"
        let data = {
            pettype: pettype,
            bcatids: '',
            scatid: scatid,
            brandid: brandid,
            agentid: this.data.subdata.agentid || '',
            price_block: combinedString,
            keyword: this.data.keyword,
            minprice: this.data.lowPrice,
            maxprice: this.data.highPrice,
            activity_region: parseInt(activityregion.join('')),
        }

        if (this.data.subdata.shipping) {
            this.getReDistributionMall(data);
        } else {
            this.setData({
                currentPage: 1
            }, () => {
                this.getProductlist(data)
            })
        }
        console.log("你点击了取消", e, this.data.history);
        const app = getApp();
        app.globalData.historylist = {
            ...this.data.subdata,
            ...data,
            historylist: [...this.data.history]
        };
        this.data.goodsList = []
        this.setData({
            isAshow: false
        }, () => {
            this.computeScrollViewHeight()
        });

    },
    /**
     * 确认筛选内容回调函数方法
     * @param {*} e 
     */
    handleOnconfirm(e) {
        this.setData({
            goodsList: []
        })
        console.log('e.detail11', e.detail, this.data.history)
        if (this.data.history.length == 0) {
            this.data.history.push({
                type: 1,
                data: []
            }, {
                type: 2,
                data: []
            }, {
                type: 3,
                data: []
            }, {
                type: 4,
                data: []
            });
        }

        e.detail.forEach((item, index) => {
            if (index == 0) {
                this.data.brandList.map(element => element.checked = false)
                this.data.brandList.forEach(element => {
                    item.selectInfo.forEach(info => {
                        if (info.brandid == element.brandid) {
                            element.checked = true;
                        }
                    })
                })
                this.data.history.forEach(element => {
                    if (element.type == 3) {
                        element.data = item.selectInfo
                    }
                })
            } else if (index == 1) {
                this.data.catList.map(element => element.checked = false)
                this.data.catList.forEach(element => {
                    item.selectInfo.forEach(info => {
                        if (info.id == element.id) {
                            element.checked = true;
                        }
                    })
                })
                this.data.history.forEach(element => {
                    if (element.type == 2) {
                        element.data = item.selectInfo
                    }
                })
            } else if (index == 2) {
                this.data.petTypeList.map(element => element.checked = false)
                this.data.petTypeList.forEach(element => {
                    item.selectInfo.forEach(info => {
                        if (info.id == element.id) {
                            element.checked = true;
                        }
                    })
                })
                this.data.history.forEach(element => {
                    if (element.type == 1) {
                        element.data = item.selectInfo
                    }
                })
            } else if (index == 3) {
                this.data.history.forEach(element => {
                    if (element.type == 4) {
                        element.data = this.data.isinternal == 2 ? [{
                            id: 1,
                            name: '进口商品'
                        }] : item.selectInfo
                    }
                })
            }
        })
        wx.nextTick(() => {
            this.setData({
                history: this.data.history,
                currentPage: 1
            })
        })
        // 使用map方法取出id并组成字符串
        let pettype = this.data.history[0].data.map(item => {
            if (item.numId) {
                return item.numId;
            } else if (item.id) {
                return item.id;
            }
        }).join(',');
        let scatid = this.data.history[1].data.map(item => item.id).join(',');
        let brandid = this.data.history[2].data.map(item => item.brandid).join(',');
        let activityregion = this.data.history[3].data.map(item => item.id);
        let combinedString = ''
        if (this.data.lowPrice != '' && this.data.highPrice != '') {
            combinedString = this.data.lowPrice + ',' + this.data.highPrice;
        } else {
            combinedString = ''
        }
        console.log('pettype', pettype, scatid, brandid, combinedString); // 输出结果为 "96,4,9"
        let data = {
            pettype: pettype,
            bcatids: '',
            scatid: scatid,
            brandid: brandid,
            agentid: this.data.subdata.agentid || '',
            price_block: combinedString,
            keyword: this.data.keyword,
            minprice: this.data.lowPrice,
            maxprice: this.data.highPrice,
            activity_region: parseInt(activityregion.join('')),
        }

        if (this.data.subdata.shipping) {
            this.getReDistributionMall(data);
        } else {
            this.setData({
                currentPage: 1
            }, () => {
                this.getProductlist(data)
            })
        }
        console.log("你点击了确认筛选内容", e, this.data.history);
        const app = getApp();
        app.globalData.historylist = {
            ...this.data.subdata,
            ...data,
            historylist: [...this.data.history]
        };
        this.data.goodsList = []
        this.setData({
            isAshow: false
        }, () => {
            this.computeScrollViewHeight()
        });
    },
    /**
     * 标签删除
     * @param {*} e 
     */
    handleDelete(e) {
        console.log('e', e.detail.value, this.data.history)
        let idToDelete = ''
        let indexToDelete = ''
        let indextipToDelete = ''
        if (e.detail.value.RefundStatus != undefined) {
            idToDelete = e.detail.value.type;
            indexToDelete = e.detail.value.id;
            this.data.history[2] = {
                data: [{
                    brandid: this.data.history[2].data[0].id || this.data.history[2].data[0].brandid,
                    name: this.data.history[2].data[0].name,
                    thumb: this.data.history[2].data[0].thumb,
                    type: 3,

                }],
                type: 3
            }

        } else {
            idToDelete = e.detail.value.type || e.detail.value.classCname || e.detail.value.parentId;
            indexToDelete = e.detail.value.id || e.detail.value.brandid;
            indextipToDelete = e.detail.value.tip || e.detail.value.tip;
        }
        let  newHistory = ''
        let  newHistoTo = ''
        let  newHistoryRo = ''
        if (indextipToDelete == true) {
            let newData;
            this.data.history = this.data.history.map(element => {
                if (element.type == 4) {
                    newData = element.data.filter((item, index) => item.id !== indexToDelete);
                    console.log('newData', newData);
                    return {
                        type: element.type,
                        data: newData
                    };
                }
                return element; // 返回原始元素，除非类型为4
            });
         
        } else {
            // 假设要删除的数据在数组中的索引
            this.data.history = this.data.history.map(element => {
               
                if (element.type == idToDelete) {
                    let newData
                    if (element.type == 3) {
                        newData = element.data.filter((item, index) => item.brandid !== indexToDelete);

                    } else {
                        newData = element.data.filter((item, index) => item.id !== indexToDelete);
                    }
                    return {
                        type: element.type,
                        data: newData
                    };
                } else {
                    return element;
                }
            });
            this.data.history.forEach(item => {
                if (item.type == 4) {
                    if (e.detail.value.id == 1 && e.detail.value.name == '进口商品') {
                        item.data = []
                        this.setData({
                            isinternal: 1
                        })
                    } else {
                        item.data = []
                        this.setData({
                            isinternal: 1
                        })
                    }
                }
            })
        }

        if (e.detail.value.type == 3) {
            this.data.brandList.forEach(item => {
                if (item.brandid == e.detail.value.brandid) {
                    item.checked = false
                }

            })
        } else if (e.detail.value.type == 2) {
            this.data.catList.forEach(item => {
                if (item.id == e.detail.value.id) {
                    item.checked = false
                }
            })
        } else if (e.detail.value.type == 1) {
            this.data.petTypeList.forEach(item => {
                if (item.id == e.detail.value.id) {
                    item.checked = false
                }
            })
        }
        console.log("----------", this.data.history, newHistory)
        this.setData({
            history: this.data.history,
            currentPage: 1,
            kFlag: true
        });
        // 使用map方法取出id并组成字符串
        let pettype = this.data.history[0].data.map(item => {
            if (item.numId) {
                return item.numId;
            } else if (item.id) {
                return item.id;
            }
        }).join(',');
        let scatid = this.data.history[1].data.map(item => item.id).join(',');
        let brandid = this.data.history[2].data.map(item => item.brandid).join(',');
        let activityregion = this.data.history[3].data.map(item => item.id);
        console.log('pettype2', pettype, scatid, brandid); // 输出结果为 "96,4,9"
        let data = {
            pettype: pettype,
            bcatids: '',
            scatid: scatid,
            agentid: this.data.subdata.agentid || '',
            brandid: brandid,
            keyword: this.data.keyword,
            minprice: this.data.lowPrice,
            maxprice: this.data.highPrice,
            activity_region: parseInt(activityregion.join('')),
        }
        console.log('this.data.subdata.shipping', this.data.subdata.shipping)
        if (this.data.subdata.shipping) {
            this.getReDistributionMall(data);
        } else {
            this.setData({
                currentPage: 1
            }, () => {
                this.getProductlist(data)
            })
        }
        const app = getApp();
        app.globalData.historylist = {
            ...this.data.subdata,
            ...data,
            historylist: [...this.data.history]
        };
        this.data.goodsList = []
        this.computeScrollViewHeight()
    },
    /**
     * 是否为进口商品
     * @param {*} e 
     */
    onSwitchChange(e) {
        this.setData({
            isinternal: e.detail.value ? 2 : 1
        })
    },
    /**
     * 处理最低价输入事件
     */
    onInputLowPrice(e) {
        this.data.lowPrice = e.detail.lowPrice;
        // 处理最低价输入事件
        this.setData({
            'priceData.lowPrice': e.detail.lowPrice
        });
    },
    onInputHighPrice(e) {
        this.data.highPrice = e.detail.highPrice;
        // 处理最高价输入事件
        this.setData({
            'priceData.highPrice': e.detail.highPrice
        });
    },
    /**
     * 重置筛选内容回调函数方法
     */
    handleOnReset(e) {
        this.setData({
            priceData: {
                lowPrice: '',
                highPrice: ''
            },
            lowPrice: '',
            highPrice: '',
            isinternal: ''
        });
    },
    /**
     * 跳转商品详情页回调函数方法
     */
    handleGoodsDetail(e) {
        const {
            value
        } = e.currentTarget.dataset
        const params = {
            goodsId: "",
            area: "",
            detailType: 1,
            act: "good_detail"
        }
        if (value) {
            const {
                goodsid,
                id
            } = e.currentTarget.dataset.value
            if (goodsid) {
                params.goodsId = goodsid
            } else {
                params.goodsId = id
            }
        } else {
            const {
                id
            } = e.detail
            params.goodsId = id
        }
        wx.navigateTo({
            url: `/pages/goods_detail/index?data=${JSON.stringify(params)}`,
        })
    },
    /**
     * 促销标题
     */
    parseTtile(value) {
        let actstr = ""
        value.buy = value.buy.replaceAll(".00", "")
        value.derate = value.derate.replaceAll(".00", "")
        // 满额活动(type:1,2,5,6) buy <=0 或者 满件活动(type:3,4) buy <=1时显示简称
        switch (value.type) {
            case "1":
                if (value.buy <= 0) {
                    actstr = `立减${value.derate}元`
                } else {
                    actstr = `满${value.buy}元减${value.derate}元`
                }
                break
            case "2":
                if (value.buy <= 0) {
                    actstr = `送${value.derate}件`
                } else {
                    actstr = `满${value.buy}元送${value.derate}件`
                }
                break
            case "3":
                actstr = `满${value.buy}件送${value.derate}件`
                break
            case "4":
                if (value.buy <= 1) {
                    actstr = `${value.derate / 10}折`
                } else {
                    actstr = `满${value.buy}件${value.derate / 10}折`
                }
                break
            case "5":
                if (value.buy <= 0) {
                    actstr = `${value.derate / 10}折`
                } else {
                    actstr = `满${value.buy}元打${value.derate / 10}折`
                }
                break
            case "6":
                if (value.buy <= 0) {
                    actstr = `立减${value.derate}元`
                } else {
                    actstr = `满${value.buy}元送${value.derate}元`
                }
                break
            default:
                break
        }
        return actstr
    },
    colist(val) {
        console.log('e', val, this.data.subdata)
        const {
            value
        } = val.currentTarget.dataset
        getNavigationbar({
            act: 'agent_coupon_collect',
            id: value.id,
        }).then(res => {
            console.log('', res)

            if (res) {
                getApp().Tips({
                    title: '领取成功'
                })
                this.getActivities(this.data.subdata)
            }
        });
    },
    /**
     * 供应商活动
     */
    getActivities(item) {
        getNavigationbar({
            act: 'agent_acticity',
            agentid: item.agentid || '',
        }).then(res => {
            res.coupon_list.map(item => {

                if (item.discounttype == '2') {
                    item.edu = item.edu / 10
                } else if (item.discounttype == '3') {
                    item.edu = item.edu / 10
                }
            })
            console.log('供应商活动', res)
            wx.nextTick(() => {
                const arr = res
                arr.brand_activity.forEach(item => {
                    item.offerTitle = this.parseTtile(item)
                })

                this.setData({
                    goodsbrand_activity: arr
                }, () => {
                    this.computeScrollViewHeight()
                })
            })
        })
    },
    /**
     * 选择商品规格加入购物车回调函数方法
     */
    handleJoinCart(e) {
        console.log('e', e)
        let data = {
            ...e.currentTarget.dataset.value
        }
        if (this.data.obj.shop_status == 0 || this.data.obj.shop_status == 1) {
            this.setData({
                isAhow: true,
            })
            return
        }
        //详细接口
        getNavigationbar({
            act: 'good_detail',
            id: data.id
        }).then(res => {
            this.setData({
                isSpecs: true,
                objData: res
            })
        })

    },
    /**
     * 完成规格选择将商品添加至购物车
     */
    handleConfirm(e) {
        console.log('传回', e)
        let data = e.detail
        this.setData({
            isSpecs: false
        })
        getNavigationbar({
            act: 'cart',
            id: data.commodityId || '',
            propertyid: data.data.propertyid || '',
            numbers: data.count || '',
        }).then(res => {
            console.log('添加编辑购物车-一件代发', res)
            if (res.result == 101) {
                wx.nextTick(() => {
                    getApp().Tips({
                        title: res.msg
                    })
                })
            } else {
                wx.nextTick(() => {
                    getApp().Tips({
                        title: "商品已添加至购物车"
                    })
                })

            }
            this.getShoppingCartList();
        });

    },
    /**
     * 商品列表
     */
    getProductlist(item) {
        this.setData({
            item: item,
            orderFlag: true
        })
        getNavigationbar({
            act: 'pro_list',
            agentid: item.agentid || '',

            activity_region: item.activity_region || '',
            price_block: item.price_block || '',
            pettype: item.pettype || '',
            bcatid: '',
            scatid: item.scatid || '',
            isinternal: this.data.isinternal || '',
            brandid: item.brandid || '',
            keyword: item.keyword || '',
            source: '',
            lack_inventory: '1',
            p: this.data.currentPage, // 当前页码
        }).then(res => {
            if (res && res.length) {
                res.forEach(element => {

                    if (item.pettype == undefined && item.scatid == undefined && item.brandid == undefined) {
                        Object.assign(element, {
                            tips: 0 //普通
                        })
                    } else {
                        Object.assign(element, {
                            tips: 2 //京东
                        })
                    }
                    if (this.data.obj.shop_status == 0 || this.data.obj.shop_status == 1) {
                        element.sellprice = '***'
                        // element.replace_price = '***'
                        element.marketprice = '***'
                    }
                });

                const result = res.map(obj => {
                    const uniqueIds = [...new Set(obj.activity_list.map(item => item.range))];
                    const filteredActive = uniqueIds.map(range => obj.activity_list.filter(item => item.range === range).pop());
                    return {
                        ...obj,
                        activity: filteredActive.reverse(),
                        activity_list: filteredActive.reverse(),
                        integerPart: obj.sellprice.split('.')[0],
                        decimalPart: obj.sellprice.split('.')[1]
                    };
                });
                console.log('分类数据列表', res)
                wx.nextTick(() => {
                    // 更新页面数据
                    this.setData({
                        goodsList: this.data.goodsList.concat(result) // 将新数据追加到原有数据后面
                    })
                })
            }


        })
    },
    handleScrollToLower() {
        console.log('触发到底部提示打印');
        // 使用map方法取出id并组成字符串
        let pettype = this.data.history[0].data.map(item => {
            if (item.numId) {
                return item.numId;
            } else if (item.id) {
                return item.id;
            }
        }).join(',');
        let scatid = this.data.history[1].data.map(item => item.id).join(',');
        let brandid = this.data.history[2].data.map(item => item.brandid).join(',');
        let combinedString = ''
        if (this.data.lowPrice != '' && this.data.highPrice != '') {
            combinedString = this.data.lowPrice + ',' + this.data.highPrice;
        } else {
            combinedString = ''
        }
        let activityregion = this.data.history[3].data.map(item => item.id);
        console.log('pettype2', pettype, scatid, brandid); // 输出结果为 "96,4,9"
        let data = {
            pettype: pettype,
            bcatids: '',
            scatid: scatid,
            brandid: brandid,
            keyword: this.data.keyword,
            agentid: this.data.subdata.agentid || '',
            minprice: this.data.lowPrice,
            maxprice: this.data.highPrice,
            currentPage: this.data.currentPage + 1,
            price_block: combinedString,
            counts: 10,
            activity_region: parseInt(activityregion.join('')),
        }
        this.setData({
            currentPage: this.data.currentPage + 1,
            loading: true
        });
        this.getProductlist(data);
    },
    /**
     * 计算页面可滚动区域的动态高度
     */
    computeScrollViewHeight() {
        let that = this
        let query = wx.createSelectorQuery().in(this)
        query.select('.content').boundingClientRect()
        query.exec(res => {
            // 同步获取系统信息
            const systemInfo = wx.getSystemInfoSync();
            // 计算底部安全距离
            const safeBottom = systemInfo.screenHeight - systemInfo.safeArea.bottom;
            let contentHeight = res[0].height;
            that.setData({
                scrollViewHeight: contentHeight - safeBottom
            })
        })
    },
    onPull() {
        let agentid = this.data.subdata.agentid

        wx.navigateTo({
            url: `/pages/brand_centent/index?agentid=${agentid}`,
        })
    },
    /**
     * 分类
     */
    getBrandcatlist() {
        console.log('this.data.subdata.agentid', this.data.subdata.agentid)
        getNavigationbar({
            act: 'brand_cat_list',
            keyword: '',
            agentid: this.data.subdata.agentid || '',
        }).then(res => {
            this.data.lisrcot.forEach(item => {
                item.data.forEach(itemj => {
                    res.brand_list.forEach(element => {
                        if (element.brandid == itemj.brandid) {
                            console.log('(------------------------------------)')
                            element.checked = true
                        }
                    });
                });

            });
            this.setData({
                brandList: res.brand_list,
                catList: res.cat_list,
                petTypeList: res.pettype_list
            });

        });
    },
    onShareAppMessage: function () {

        let obj = {
            ...this.data.subdata,
        }
        console.log('agent_thumb', obj)
        let objStr = encodeURIComponent(JSON.stringify(obj));
        return {
            title: obj.agent_name || obj.agentname,
            path: '/pages/brand_detail/index?obj=' + objStr,
            imageUrl: `https://static.chonglaoban.cn` + obj.agent_thumb // 分享的图片链接
        }
    },
    onShareTimeline: function () {
        let obj = {
            ...this.data.subdata,
        }
        let objStr = encodeURIComponent(JSON.stringify(obj));

        return {
            title: obj.agent_name || obj.agentname,
            path: '/pages/brand_detail/index?obj=' + objStr,
            imageUrl: `https://static.chonglaoban.cn` + obj.agent_thumb // 分享的图片链接
        }
    },
    onClickLeft() {
        console.log('跳转', this.data.navigateToUrl)
        if (this.data.navigateToUrl == 'goods_detail') {
            wx.navigateBack()
            return
        }
        // else {
        //     wx.switchTab({
        //         url: `/pages/${this.data.navigateToUrl}/index`
        //     })
        // }
        wx.switchTab({
            url: `/pages/${this.data.navigateToUrl}/index`
        })

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let objStr = decodeURIComponent(options.obj);
        let obj = JSON.parse(objStr);
        this.data.subdata = {
            ...obj
        }
        this.data.navigateToUrl = obj.url
        this.setData({
            subdata: obj,
            navigateToUrl: obj.url
        })

        console.log('来', obj)
        let res = wx.getStorageSync('USER')
        this.data.obj = res
        let historylist = [];
        if (obj.keyword && obj.flag == 0) {
            // 处理有关键字的情况
            this.setData({
                keyword: obj.keyword
            })
        } else if (obj.flag == 2) {
            this.data.keyword = obj.keyword;
            this.setData({
                keyword: obj.keyword
            })
            this.setData({
                subdata: obj.historyList
            })
            historylist = obj.historyList.historylist
            obj = {
                ...obj.historyList,
                ...obj
            }
        } else {
            let type1Data = obj.classAname ? [{
                ...obj.classAname
            }] : [];
            let type2Data = obj.classBname ? [{
                ...obj.classBname
            }] : [];
            let type3Data
            console.log('11111111', obj.name)
            if (obj.brand_list != undefined || obj.jd_extra != undefined || obj.detail != undefined || obj.show != true || obj.RefundStatus.length > 0) {
                if (obj.name == undefined) {
                    type3Data = [];
                } else {
                    type3Data = [];
                }

            } else {
                if (obj.name == undefined) {
                    type3Data = [];
                } else {
                    type3Data = [{
                        ...obj
                    }];
                }

            }

            historylist.push({
                type: 1,
                data: type1Data
            }, {
                type: 2,
                data: type2Data
            }, {
                type: 3,
                data: type3Data
            }, {
                type: 4,
                data: []
            });
            this.data.lisrcot.push({
                type: 1,
                data: type1Data
            }, {
                type: 2,
                data: type2Data
            }, {
                type: 3,
                data: type3Data
            }, {
                type: 4,
                data: []
            });
        }



        const app = getApp();
        app.globalData.historylist = {
            ...this.data.subdata,
            historylist: [...historylist, ...this.data.history]
        };
        console.log(' this.data.keyword ', historylist)

        wx.nextTick(() => {
            this.setData({
                history: [...historylist],
                navigateToUrl: obj.url
            });
        });
        this.getProductlist({
            ...obj
        });
        this.getActivities({
            ...obj
        })
        this.getBrandcatlist()
        this.getShoppingCartList()
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
        // this.getActivities({
        //     ...this.data.subdata
        // })

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

})